//
//  DetailViewController.swift
//  swift项目
//
//  Created by 龚昕炜 on 16/7/26.
//  Copyright © 2016年 龚昕炜. All rights reserved.
//

import UIKit

class DetailViewController: UIViewController {
    
    var model: Person?
    
    var closure: (()->())?
    
    var idTextField: UITextField?
    
    var pwdTextField: UITextField?

    override func viewDidLoad() {
        super.viewDidLoad()
        
        self.view.backgroundColor = UIColor.whiteColor()

        let idTextField = UITextField(frame: CGRect(x: 20, y: 80, width: 300, height: 40))
        idTextField.borderStyle = UITextBorderStyle.RoundedRect
        idTextField.placeholder = "账号"
        let pwdTextField = UITextField(frame: CGRect(x: 20, y: 140, width: 300, height: 40))
        pwdTextField.borderStyle = UITextBorderStyle.RoundedRect
        pwdTextField.placeholder = "密码"
        
        self.view.addSubview(idTextField)
        self.idTextField = idTextField
        self.view.addSubview(pwdTextField)
        self.pwdTextField = pwdTextField
        
        idTextField.text = model!.name
        pwdTextField.text = String(model!.age)
        
        self.navigationItem.rightBarButtonItem = UIBarButtonItem(title: "save", style: UIBarButtonItemStyle.Plain, target: self, action: "run")
    }

    func run()
    {
       model!.name = self.idTextField?.text
        model!.age = Int((self.pwdTextField?.text)!) ?? 0
        closure!()
//        self.navigationController!.popViewControllerAnimated(true)
    }
    

    /*
    // MARK: - Navigation

    // In a storyboard-based application, you will often want to do a little preparation before navigation
    override func prepareForSegue(segue: UIStoryboardSegue, sender: AnyObject?) {
        // Get the new view controller using segue.destinationViewController.
        // Pass the selected object to the new view controller.
    }
    */

}
